import pygame

class Ship():
	""""飞船"""
	def __init__(self, ai_game):
		"""初始化飞船"""
		# 获取屏幕和屏幕的矩形
		self.screen = ai_game.screen
		self.screen_rect = ai_game.screen.get_rect()
		self.settings = ai_game.settings

		# 飞船图片，以及飞船的矩形
		self.image = pygame.image.load("images/plane.jpg")
		self.rect = ballrect = self.image.get_rect()

		# 设置飞船的位置
		self.rect.midbottom = self.screen.get_rect().midbottom

		self.moving_right = False
		self.moving_left = False
		self.moving_up = False
		self.moving_down = False

		self.x = float(self.rect.x)
		self.y = float(self.rect.y)

	def update(self):
		if self.moving_right and self.rect.right < self.screen_rect.right:
			self.x += self.settings.ship_speed
		if self.moving_left and self.rect.left > self.screen_rect.left:
			self.x -= self.settings.ship_speed
		if self.moving_up and self.rect.top > self.screen_rect.top:
			self.y -= self.settings.ship_speed
		if self.moving_down and self.rect.bottom < self.screen_rect.bottom:
			self.y += self.settings.ship_speed

		self.rect.x = self.x
		self.rect.y = self.y

		if self.rect.x > self.screen.get_rect().right:
			self.rect.x = self.screen.get_rect().right
	def blit_me(self):
		self.screen.blit(self.image, self.rect)
